﻿using ConfExpert.Utility;
using System;
using System.Data;
using System.Drawing;
using System.IO;
using System.Windows.Forms;

namespace ConfOrder
{
    public partial class DetailA : XPopupForm
    {
        public DetailA(int AksesuarId)
        {
            InitializeComponent();
            DataTable dt = AppSession.DataManager.ExecuteDataTable("GetAksPhoto", AksesuarId);
            if (dt.Rows.Count > 0)
            {
                this.Text = dt.Rows[0]["StokKod"].ToString();
                Image img = ConvertByteArrayToImage((byte[])dt.Rows[0]["Photo2"]);
                //Image img = Image.FromFile(FileName);
                pictureEdit1.Image = img;
                pictureEdit1.Width = img.Width;
                pictureEdit1.Height = img.Height;
                pictureEdit1.Properties.SizeMode = DevExpress.XtraEditors.Controls.PictureSizeMode.Squeeze;
                this.Width = img.Width + 25;
                this.Height = img.Height + 45;
                this.StartPosition = FormStartPosition.CenterScreen;
            }
        }


        public Image ConvertByteArrayToImage(byte[] byteArray)
        {
            try
            {
                if (byteArray != null)
                {
                    MemoryStream ms = new MemoryStream(byteArray, 0, byteArray.Length);
                    ms.Write(byteArray, 0, byteArray.Length);
                    return Image.FromStream(ms, true);
                }
            }
            catch (Exception) { return null; }
            return null;
        }
    }
}
